package com.t16;

import net.mindview.util.Generator;

import java.util.*;

/**
 * Created by xuyiwei on 2018/8/11.
 */
public class CompType implements Comparable<CompType> {
    int i;
    int j;
    private static int count = 1;
    public CompType(int i, int j) {
        this.i = i;
        this.j = j;
    }
    @Override
    public int compareTo(CompType o) {
        //现在是按i的升序排  如果返回1则不换  如果不是则替换
        return (i<o.i?-1:(i==o.i?0:1));
    }
    private static Random r = new Random(47);
    public static Generator<CompType> generator(){
        return new Generator<CompType>() {
            @Override
            public CompType next() {
                return new CompType(r.nextInt(100),r.nextInt(100));
            }
        };
    }

    public static void main(String[] args) {
        CompType[] a = Generated.array(new CompType[12],generator());
        //按CompareTo的排序 现在是升序
        Arrays.sort(a);
        System.out.println(Arrays.binarySearch(a,a[3]));
        //反转
        Arrays.sort(a, Collections.reverseOrder());
        System.out.println(Arrays.binarySearch(a,a[4],Collections.reverseOrder()));

    }
}
